package com.darcytech.debezium.core.pool;

import com.darcytech.debezium.core.kafka.connect.model.Config;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class RegisterGroup {

    private final String group;

    private final List<Config> configs;

    public String getGroup() {
        return group;
    }

    public List<Config> getConfigs() {
        return configs;
    }

    public RegisterGroup(String group, String kafkaServers, List<ConnectorInfo> groupConnectorInfos, Map<String, String> serverIdMap) {
        this.group = group;
        List<Config> configs = new ArrayList<>();
        for (ConnectorInfo connectorInfo : groupConnectorInfos) {
            Config config = new Config(kafkaServers, connectorInfo.getHostName(), String.valueOf(connectorInfo.getPort()), connectorInfo.getUserNameExpression(),
                    connectorInfo.getPasswordExpression(), serverIdMap.get(connectorInfo.getConnectorName()), connectorInfo.getGroup(),
                    connectorInfo.getDataBases(), connectorInfo.getTables(), connectorInfo.getGroupSchemaTopic(), connectorInfo.getConnectorName());
            configs.add(config);
        }
        this.configs = Collections.unmodifiableList(configs);
    }

}
